package com.scott.customer.service;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import org.springframework.web.client.RestTemplate;

/**
 * @author guanjiwei
 */

public class MyHystrix extends HystrixCommand<String> {

    private RestTemplate restTemplate;

    public MyHystrix(String group, RestTemplate restTemplate) {
        super(HystrixCommandGroupKey.Factory.asKey(group));
        this.restTemplate = restTemplate;
    }

    @Override
    protected String run() throws Exception {
        System.out.println(Thread.currentThread().getName());
        return restTemplate.getForEntity("http://10.201.10.163:8087/say", String.class).getBody();
//        return restTemplate.getForEntity("http://192.168.1.5:8087/say", String.class).getBody();
    }

    @Override
    protected String getFallback() {
        return "error ";
    }
}
